home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / Found / FWString / FWPStr.h < prev    next >
Encoding:
Text File  |  1996-09-17  |  29.2 KB  |  858 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWPStr.h
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #ifndef FWPSTR_H
  11. #define FWPSTR_H
  12.  
  13. #ifndef FWEXCLIB_H
  14. #include "FWExcLib.h"
  15. #endif
  16.  
  17. #ifndef FWARDYNA_H
  18. #include "FWArDyna.h"
  19. #endif
  20.  
  21. #ifndef SLTXTPAR_H
  22. #include "SLTxtPar.h"
  23. #endif
  24.  
  25. #ifndef SLSTRREP_H
  26. #include "SLStrRep.h"
  27. #endif
  28.  
  29. //========================================================================================
  30. //    Forward declarations
  31. //========================================================================================
  32.  
  33. struct ODIText;
  34. class FW_CReadableStream;
  35. class FW_CWritableStream;
  36. class FW_CString;
  37.  
  38. //========================================================================================
  39. //    CLASS FW_CString
  40. //
  41. //    Characters in strings may occupy one, two, and possibly more bytes.
  42. //  The number of characters in the string is therefore not necessarily equal 
  43. //    to the number of bytes in the string.
  44. //
  45. //    The "length" of the string is measured in characters.
  46. //  The "byteLength" of the string is measured in bytes.
  47. //  The "capacity" of the string is measure in bytes.
  48. //
  49. //========================================================================================
  50.  
  51. class FW_CString
  52. {
  53. public:
  54.     FW_DECLARE_CLASS
  55.     FW_DECLARE_AUTO(FW_CString)
  56.     
  57. //----------------------------------------------------------------------------------------
  58. //    Initialization/Destruction
  59. //
  60. public:
  61.     virtual ~FW_CString();
  62.     FW_CString();
  63.     FW_CString(const FW_CString& other);
  64.     FW_CString(FW_HString rep);
  65.  
  66.     FW_CString(ODIText *text);
  67.     FW_CString(const char* string);
  68.     FW_CString(const char* bytes, FW_ByteCount byteLength);
  69.  
  70.     FW_CString(const char* string, const FW_Locale& locale);
  71.     FW_CString(const char* bytes, FW_ByteCount byteLength, const FW_Locale& locale);
  72.     
  73.     operator FW_HString() const { return fRep; }
  74.     operator FW_HString*();
  75.  
  76. //----------------------------------------------------------------------------------------
  77. //    Character access
  78. //
  79. public:
  80.     FW_LChar operator[](FW_CharacterPosition position) const;
  81.         // This function may be expensive for some character sets!
  82.         // Note that it returns a "long character", which may be 1, 2, or possibly more bytes
  83.  
  84. //----------------------------------------------------------------------------------------
  85. //    Assignment
  86. //
  87. public:
  88.     FW_CString&  operator=(const FW_CString& other);
  89.     FW_CString&  operator=(ODIText *text);
  90.     FW_CString&  operator=(const char* string);
  91.     
  92. //----------------------------------------------------------------------------------------
  93. //    Storage Manipulation
  94. //
  95. public:
  96.     FW_ByteCount GrowCapacity(FW_ByteCount count);
  97.         // If possible, grow the capacity to count bytes.
  98.         // Return the actual capacity, which may be less or more than count.
  99.     
  100. //----------------------------------------------------------------------------------------
  101. //    Basic accessors
  102. //
  103. public:
  104.     FW_ByteCount GetByteLength() const;
  105.         // Return the number of bytes actually in use for the string
  106.  
  107.     FW_CharacterCount GetCharacterLength() const;
  108.         // Return the number of characters actually in use for the string.
  109.         // Note that with some character sets this may be significantly more expensive
  110.         // to call than GetByteLength!
  111.  
  112.     FW_ByteCount GetCapacity() const;
  113.         // Return the number of bytes that may currently be used without growing capacity.
  114.         // Note that GrowCapacity can be used to extend the capacity beyond the current limit.
  115.     
  116.     void GetLocale(FW_Locale& locale) const;
  117.     
  118.     FW_Boolean IsEmpty() const;
  119.         // Returns true if the string is the empty string, i.e. it's bytelength is 0.
  120.     
  121. //----------------------------------------------------------------------------------------
  122. //    Access to internals, use with caution!
  123. //
  124. public:
  125.     const char* RevealBuffer() const;
  126.         // This function is provided for convenience but is potentially dangerous!!
  127.         // Do not cast away const and then modify the string!
  128.         // Do not save the return value and expect it to be valid after calling
  129.         // any string manipulation method that modifies the string!
  130.         // NOTE: This is not a NUL-terminated string! Use GetByteLength to determine
  131.         // how many bytes may be accessed.
  132.  
  133.     ODIText* RevealODIText() const;
  134.         // This function is provided for convenience but is potentially dangerous!!
  135.         // RevealODIText may be used when passing a String to an OpenDoc interface
  136.         // that takes an ODIText* as an "in" parameter.  Do not use this function to
  137.         // receive a string from OpenDoc!  Also, do not save the return value!
  138.         // Any string manipulation method that modifies the string may invalidate
  139.         // ODIText.
  140.     
  141.     FW_Locale* RevealLocale() const;
  142.         // Used by TextReaders
  143.  
  144. //----------------------------------------------------------------------------------------
  145. // Streaming
  146. public:
  147.  
  148.     static void* Read(FW_CReadableStream& stream, FW_ClassTypeConstant type);
  149.  
  150.     static void Write(FW_CWritableStream& stream, FW_ClassTypeConstant type, const void *object);
  151.  
  152.     FW_CReadableStream& PrivRead(FW_CReadableStream& stream);
  153.  
  154.     FW_CWritableStream& PrivWrite(FW_CWritableStream& stream) const;
  155.  
  156.     friend inline FW_CReadableStream& operator>>(FW_CReadableStream& stream, FW_CString& string);
  157.     friend inline FW_CWritableStream& operator<<(FW_CWritableStream& stream, const FW_CString& string);
  158.  
  159. //----------------------------------------------------------------------------------------
  160. //    String Manipulation
  161. //
  162. public:
  163.     void Retrieve(char* destination, 
  164.                   FW_ByteCount numberBytes, 
  165.                   FW_BytePosition position) const;
  166.         // Retrieve numberBytes of bytes starting at position.
  167.         // Copy bytes into the destination.
  168.         
  169.     void Delete(FW_ByteCount numberBytes, 
  170.                 FW_BytePosition position);
  171.         // Delete numberBytes bytes, starting at position.
  172.         
  173.     void Insert(const char* bytes, 
  174.                 FW_ByteCount numberBytes,  
  175.                 FW_BytePosition position);
  176.         // Insert bytes into string just before the character at positition.
  177.         // Insert at position GetByteLength() appends the bytes.
  178.         // Insert at position 0 prepends the bytes.
  179.     
  180.     void Insert(ODIText* text, FW_BytePosition position);
  181.         // Insert text at position.
  182.     
  183.     void Insert(const FW_CString& string, FW_BytePosition position);
  184.         // Insert string at position.
  185.     
  186.     void ReplaceAll(ODIText* text);
  187.         // Replace entire contents of this string with text.
  188.     
  189.     void ReplaceAll(const FW_CString& other);
  190.         // Replace entire contents of this string with string.
  191.     
  192.     void ReplaceAll(const char* bytes, FW_ByteCount numberBytes);
  193.         // Replace entire contents of this string with bytes.
  194.  
  195.     void ReplaceAll(const char* string);
  196.         // Replace entire contents of this string with (nul-terminated) string.
  197.     
  198.     void ReplaceAll(const FW_PascalChar* pascalString);
  199.         // Replace entire contents of this string with pascal string.
  200.  
  201.     void ReplaceAll(const char* string, const FW_Locale& newLocale);
  202.         // Replace entire contents of this string with (nul-terminated) string
  203.         // Also replace locale info
  204.  
  205.     void SetEmpty();
  206.         // Remove the entire contents of this string
  207.  
  208.     void SetEmpty(const FW_Locale& newLocale);
  209.         // Remove the entire contents of this string, and replace the locale info
  210.  
  211.     void Append(const FW_CString& other);
  212.         // Append string onto end of this string.
  213.     
  214.     void Append(ODIText* text);
  215.         // Append text onto end of this string.
  216.     
  217.     void Append(const char* bytes, FW_ByteCount numberBytes);
  218.         // Append bytes onto end of this string.
  219.     
  220.     void Append(const char* string);
  221.         // Append (nul-terminated) string onto end of this string.
  222.     
  223.     void Append(char character);
  224.         // Append a single character onto the end of this string.
  225.         
  226.     void Prepend(const FW_CString& other);
  227.         // Prepend string onto beginning of this string.
  228.     
  229.     void Prepend(ODIText* text);
  230.         // Prepend text onto beginning of this string.
  231.     
  232.     void Prepend(const char* bytes, FW_ByteCount numberBytes);
  233.         // Prepend bytes onto beginning of this string.
  234.         
  235.     void Prepend(const char* string);
  236.         // Prepend (nul-terminated) string onto beginning of this string.
  237.         
  238.     void Truncate(FW_BytePosition position);
  239.         // Truncate string at position.  Truncate(0) clears string.
  240.         
  241.     void operator+=(const FW_CString& other);
  242.         // Append string onto the end of this string.
  243.         
  244.     void operator+=(ODIText* text);
  245.         // Append string onto the end of this string.
  246.         
  247.     void operator+=(const char* string);
  248.         // Append (nul-terminated) string onto the end of this string.
  249.         
  250.     void operator+=(char character);
  251.         // Append a single character onto the end of this string.
  252.     
  253. //----------------------------------------------------------------------------------------
  254. //    Exporting Functions
  255. //
  256. public:
  257.     void ExportCString(char* buffer) const;
  258.         // Copy contents of this string to external C string buffer.
  259.         // buffer will contain NUL-terminated C string.
  260.         // It is client's responsibility to ensure buffer is large enough.
  261.  
  262.     void ExportPascal(FW_PascalChar* buffer) const;
  263.         // Copy contents of this string to external 'Pascal' buffer.
  264.         // buffer will contain Pascal string with length byte at buffer[0].
  265.         // It is client's responsibility to ensure buffer is large enough.
  266.  
  267. //----------------------------------------------------------------------------------------
  268. //    Numeric Conversion Functions
  269. //
  270. public:
  271.     long            ParseAsSignedInteger() const;
  272.     unsigned long    ParseAsUnsignedInteger() const;
  273.     unsigned long    ParseAsHexadecimalInteger() const;
  274.     double            ParseAsRealNumber() const;
  275.     
  276.     void            ReplaceAllAsSignedDecimalInteger(long integer);
  277.     void            ReplaceAllAsUnsignedDecimalInteger(unsigned long integer);
  278.     void            ReplaceAllAsHexadecimalInteger(unsigned long integer);
  279.     void            ReplaceAllAsRealNumber(double real, short fracDigits = 2);
  280.     
  281. //----------------------------------------------------------------------------------------
  282. //    Comparison Functions
  283. //
  284. public:
  285.     friend FW_Boolean operator==(const FW_CString& string1, const FW_CString& string2);
  286.     friend FW_Boolean operator!=(const FW_CString& string1, const FW_CString& string2);
  287.     friend FW_Boolean operator<(const FW_CString& string1, const FW_CString& string2);
  288.     friend FW_Boolean operator>(const FW_CString& string1, const FW_CString& string2);
  289.     friend FW_Boolean operator<=(const FW_CString& string1, const FW_CString& string2);
  290.     friend FW_Boolean operator>=(const FW_CString& string1, const FW_CString& string2);
  291.  
  292. //----------------------------------------------------------------------------------------
  293. //    Searching & Substitution Functions
  294. //
  295. public:
  296.  
  297.     void ToUpper();
  298.     void ToLower();
  299.  
  300.     FW_Boolean Substitute(const FW_CString& searchString,
  301.                           const FW_CString& substitutionString);
  302.     
  303.     FW_Boolean FindSubString(const FW_CString& subString,
  304.                              FW_BytePosition &foundPosition,
  305.                              FW_BytePosition startPosition=0) const;
  306.     
  307.     FW_Boolean FindCharacter(FW_LChar character,
  308.                              FW_BytePosition &foundPosition,
  309.                              FW_BytePosition startPosition=0,
  310.                              FW_FindDirection direction=FW_kForwards) const;
  311.     
  312. protected:
  313.     FW_HString    fRep;
  314. };
  315.  
  316. //----------------------------------------------------------------------------------------
  317. // Inline functions
  318. //----------------------------------------------------------------------------------------
  319.  
  320. inline FW_CReadableStream& operator>>(FW_CReadableStream& stream, FW_CString& string)
  321. {
  322.     return string.PrivRead(stream);
  323. }
  324.         
  325. inline FW_CWritableStream& operator<<(FW_CWritableStream& stream, const FW_CString& string)
  326. {
  327.     return string.PrivWrite(stream);
  328. }
  329.  
  330. //========================================================================================
  331. //    CLASS FW_CAcquireNulTerminatedString
  332. //========================================================================================
  333.  
  334. class FW_CAcquireNulTerminatedString
  335. {
  336. public:
  337.     FW_DECLARE_AUTO(FW_CAcquireNulTerminatedString)
  338.     
  339.     FW_CAcquireNulTerminatedString(const FW_CString& string);
  340.     ~FW_CAcquireNulTerminatedString();
  341.     operator const char*() const
  342.         { return fExportedString; }
  343.     
  344. private:
  345.     char* fExportedString;
  346. };
  347.  
  348. //========================================================================================
  349. //    CLASS FW_CAcquireNulTerminatedString255
  350. //========================================================================================
  351.  
  352. class FW_CAcquireNulTerminatedString255
  353. {
  354. public:
  355.     FW_CAcquireNulTerminatedString255(const FW_CString& string);
  356.     // no destructor necessary
  357.     operator const char*() const
  358.         { return fExportedString; }
  359.     
  360. private:
  361.     char fExportedString[255];
  362. };
  363.  
  364. //========================================================================================
  365. //    FW_CString inline functions
  366. //========================================================================================
  367.  
  368. //----------------------------------------------------------------------------------------
  369. //    FW_CString::GetByteLength
  370. //----------------------------------------------------------------------------------------
  371.  
  372. inline FW_ByteCount FW_CString::GetByteLength() const
  373. {
  374.     return FW_PrivString_GetByteLength(fRep);
  375. }
  376.  
  377. //----------------------------------------------------------------------------------------
  378. //    FW_CString::GetCapacity
  379. //----------------------------------------------------------------------------------------
  380.  
  381. inline FW_ByteCount FW_CString::GetCapacity() const
  382. {
  383.     return FW_PrivString_GetCapacity(fRep);
  384. }
  385.  
  386. //----------------------------------------------------------------------------------------
  387. //    FW_CString::IsEmpty
  388. //----------------------------------------------------------------------------------------
  389.  
  390. inline FW_Boolean FW_CString::IsEmpty() const
  391. {
  392.     return GetByteLength() == 0;
  393. }
  394.     
  395. //----------------------------------------------------------------------------------------
  396. //    FW_CString::GetLocale
  397. //----------------------------------------------------------------------------------------
  398.  
  399. inline void FW_CString::GetLocale(FW_Locale& locale) const
  400. {
  401.     FW_PrivString_GetLocale(fRep, &locale);
  402. }
  403.  
  404. //----------------------------------------------------------------------------------------
  405. //    FW_CString::RevealBuffer
  406. //----------------------------------------------------------------------------------------
  407.  
  408. inline const char* FW_CString::RevealBuffer() const
  409. {
  410.     return FW_PrivString_RevealBuffer(fRep);
  411. }
  412.  
  413. //----------------------------------------------------------------------------------------
  414. //    FW_CString::RevealODIText
  415. //----------------------------------------------------------------------------------------
  416.  
  417. inline ODIText* FW_CString::RevealODIText() const
  418. {
  419.     return FW_PrivString_RevealODIText(fRep);
  420. }
  421.  
  422. //----------------------------------------------------------------------------------------
  423. //    FW_CString::RevealLocale
  424. //----------------------------------------------------------------------------------------
  425. inline FW_Locale* FW_CString::RevealLocale() const
  426. {
  427.     return FW_PrivString_RevealLocale(fRep);
  428. }
  429.  
  430. //----------------------------------------------------------------------------------------
  431. //    FW_CString::Retrieve
  432. //----------------------------------------------------------------------------------------
  433.  
  434. inline void FW_CString::Retrieve(char* destination, 
  435.               FW_ByteCount numberBytes, 
  436.               FW_BytePosition position) const
  437. {
  438.     FW_PrivString_Retrieve(fRep, destination, numberBytes, position);
  439. }
  440.  
  441. //----------------------------------------------------------------------------------------
  442. //    FW_CString::Delete
  443. //----------------------------------------------------------------------------------------
  444.  
  445. inline void FW_CString::Delete(FW_ByteCount numberBytes, 
  446.             FW_BytePosition position)
  447. {
  448.     FW_PlatformError error = 0;
  449.     FW_HString rep = FW_PrivString_Delete(fRep, numberBytes, position, &error);
  450.     FW_FailOnError(error);
  451.     fRep = rep;
  452. }
  453.  
  454. //----------------------------------------------------------------------------------------
  455. //    FW_CString::Truncate
  456. //----------------------------------------------------------------------------------------
  457.  
  458. inline void FW_CString::Truncate(FW_BytePosition position)
  459. {
  460.     FW_PlatformError error = 0;
  461.     FW_HString rep = FW_PrivString_Truncate(fRep, position, &error);
  462.     FW_FailOnError(error);
  463.     fRep = rep;
  464. }
  465.  
  466. //----------------------------------------------------------------------------------------
  467. //    FW_CString::Insert
  468. //----------------------------------------------------------------------------------------
  469.  
  470. inline void FW_CString::Insert(const char* bytes, 
  471.             FW_ByteCount numberBytes,  
  472.             FW_BytePosition position)
  473. {
  474.     FW_PlatformError error = 0;
  475.     FW_HString rep = FW_PrivString_InsertBytes(fRep, bytes, numberBytes, position, &error);
  476.     FW_FailOnError(error);
  477.     fRep = rep;
  478. }
  479.  
  480. //----------------------------------------------------------------------------------------
  481. //    FW_CString::Insert
  482. //----------------------------------------------------------------------------------------
  483.  
  484. inline void FW_CString::Insert(ODIText* text, FW_BytePosition position)
  485. {
  486.     FW_PlatformError error = 0;
  487.     FW_HString rep = FW_PrivString_InsertODIText(fRep, text, position, &error);
  488.     FW_FailOnError(error);
  489.     fRep = rep;
  490. }
  491.     
  492. //----------------------------------------------------------------------------------------
  493. //    FW_CString::Insert
  494. //----------------------------------------------------------------------------------------
  495.  
  496. inline void FW_CString::Insert(const FW_CString& string, FW_BytePosition position)
  497. {
  498.     FW_PlatformError error = 0;
  499.     FW_HString rep = FW_PrivString_InsertStringRep(fRep, string.fRep, position, &error);
  500.     FW_FailOnError(error);
  501.     fRep = rep;
  502. }
  503.  
  504. //----------------------------------------------------------------------------------------
  505. //    FW_CString::ReplaceAll
  506. //----------------------------------------------------------------------------------------
  507.  
  508. inline void FW_CString::ReplaceAll(ODIText* text)
  509. {
  510.     FW_PlatformError error = 0;
  511.     FW_HString rep = FW_PrivString_ReplaceAllODIText(fRep, text, &error);
  512.     FW_FailOnError(error);
  513.     fRep = rep;
  514. }
  515.  
  516. //----------------------------------------------------------------------------------------
  517. //    FW_CString::ReplaceAll
  518. //----------------------------------------------------------------------------------------
  519.  
  520. inline void FW_CString::ReplaceAll(const FW_CString& string)
  521. {
  522.     FW_PlatformError error = 0;
  523.     FW_HString rep = FW_PrivString_ReplaceAllStringRep(fRep, string.fRep, &error);
  524.     FW_FailOnError(error);
  525.     fRep = rep;
  526. }
  527.  
  528. //----------------------------------------------------------------------------------------
  529. //    FW_CString::ReplaceAll
  530. //----------------------------------------------------------------------------------------
  531.  
  532. inline void FW_CString::ReplaceAll(const char* bytes, FW_ByteCount numberBytes)
  533. {
  534.     FW_PlatformError error = 0;
  535.     FW_HString rep = FW_PrivString_ReplaceAllBytes(fRep, bytes, numberBytes, &error);
  536.     FW_FailOnError(error);
  537.     fRep = rep;
  538. }
  539.  
  540. //----------------------------------------------------------------------------------------
  541. //    FW_CString::ReplaceAll
  542. //----------------------------------------------------------------------------------------
  543.  
  544. inline void FW_CString::ReplaceAll(const char* string)
  545. {
  546.     FW_PlatformError error = 0;
  547.     FW_HString rep = FW_PrivString_ReplaceAllBytes(fRep, string, FW_PrimitiveStringLength(string), &error);
  548.     FW_FailOnError(error);
  549.     fRep = rep;
  550. }
  551.  
  552. //----------------------------------------------------------------------------------------
  553. //    FW_CString::ReplaceAll
  554. //----------------------------------------------------------------------------------------
  555.  
  556. inline void FW_CString::ReplaceAll(const FW_PascalChar* string)
  557. {
  558.     FW_PlatformError error = 0;
  559.     FW_HString rep = FW_PrivString_ReplaceAllBytes(fRep, (const char*) (string+1), *string, &error);
  560.     FW_FailOnError(error);
  561.     fRep = rep;
  562. }
  563.  
  564. //----------------------------------------------------------------------------------------
  565. //    FW_CString::Append
  566. //----------------------------------------------------------------------------------------
  567.  
  568. inline void FW_CString::Append(ODIText* text)
  569. {
  570.     FW_PlatformError error = 0;
  571.     FW_HString rep = FW_PrivString_AppendODIText(fRep, text, &error);
  572.     FW_FailOnError(error);
  573.     fRep = rep;
  574. }
  575.     
  576. //----------------------------------------------------------------------------------------
  577. //    FW_CString::Append
  578. //----------------------------------------------------------------------------------------
  579.  
  580. inline void FW_CString::Append(const FW_CString& other)
  581. {
  582.     FW_PlatformError error = 0;
  583.     FW_HString rep = FW_PrivString_AppendStringRep(fRep, other.fRep, &error);
  584.     FW_FailOnError(error);
  585.     fRep = rep;
  586. }
  587.  
  588. //----------------------------------------------------------------------------------------
  589. //    FW_CString::Append
  590. //----------------------------------------------------------------------------------------
  591.  
  592. inline void FW_CString::Append(const char* bytes, FW_ByteCount numberBytes)
  593. {
  594.     FW_PlatformError error = 0;
  595.     FW_HString rep = FW_PrivString_AppendBytes(fRep, bytes, numberBytes, &error);
  596.     FW_FailOnError(error);
  597.     fRep = rep;
  598. }
  599.  
  600. //----------------------------------------------------------------------------------------
  601. //    FW_CString::Append
  602. //----------------------------------------------------------------------------------------
  603.  
  604. inline void FW_CString::Append(const char* string)
  605. {
  606.     FW_PlatformError error = 0;
  607.     FW_HString rep = FW_PrivString_AppendBytes(fRep, string, FW_PrimitiveStringLength(string), &error);
  608.     FW_FailOnError(error);
  609.     fRep = rep;
  610. }
  611.  
  612. //----------------------------------------------------------------------------------------
  613. //    FW_CString::Append
  614. //----------------------------------------------------------------------------------------
  615.  
  616. inline void FW_CString::Append(char character)
  617. {
  618.     FW_PlatformError error = 0;
  619.     FW_HString rep = FW_PrivString_AppendBytes(fRep, &character, 1, &error);
  620.     FW_FailOnError(error);
  621.     fRep = rep;
  622. }
  623.  
  624. //----------------------------------------------------------------------------------------
  625. //    FW_CString::Prepend
  626. //----------------------------------------------------------------------------------------
  627.  
  628. inline void FW_CString::Prepend(const FW_CString& string)
  629. {
  630.     FW_PlatformError error = 0;
  631.     FW_HString rep = FW_PrivString_PrependStringRep(fRep, string.fRep, &error);
  632.     FW_FailOnError(error);
  633.     fRep = rep;
  634. }
  635.  
  636. //----------------------------------------------------------------------------------------
  637. //    FW_CString::Prepend
  638. //----------------------------------------------------------------------------------------
  639.  
  640. inline void FW_CString::Prepend(ODIText* text)
  641. {
  642.     FW_PlatformError error = 0;
  643.     FW_HString rep = FW_PrivString_PrependODIText(fRep, text, &error);
  644.     FW_FailOnError(error);
  645.     fRep = rep;
  646. }
  647.  
  648. //----------------------------------------------------------------------------------------
  649. //    FW_CString::Prepend
  650. //----------------------------------------------------------------------------------------
  651.  
  652. inline void FW_CString::Prepend(const char* bytes, FW_ByteCount numberBytes)
  653. {
  654.     FW_PlatformError error = 0;
  655.     FW_HString rep = FW_PrivString_PrependBytes(fRep, bytes, numberBytes, &error);
  656.     FW_FailOnError(error);
  657.     fRep = rep;
  658. }
  659.  
  660. //----------------------------------------------------------------------------------------
  661. //    FW_CString::Prepend
  662. //----------------------------------------------------------------------------------------
  663.  
  664. inline void FW_CString::Prepend(const char* string)
  665. {
  666.     FW_PlatformError error = 0;
  667.     FW_HString rep = FW_PrivString_PrependBytes(fRep, string, FW_PrimitiveStringLength(string), &error);
  668.     FW_FailOnError(error);
  669.     fRep = rep;
  670. }
  671.  
  672. //----------------------------------------------------------------------------------------
  673. //    FW_CString::operator+=
  674. //----------------------------------------------------------------------------------------
  675.  
  676. inline void  FW_CString::operator+=(const FW_CString& other)
  677. {
  678.     FW_PlatformError error = 0;
  679.     FW_HString rep = FW_PrivString_AppendStringRep(fRep, other.fRep, &error);
  680.     FW_FailOnError(error);
  681.     fRep = rep;
  682. }
  683.  
  684. //----------------------------------------------------------------------------------------
  685. //    FW_CString::operator+=
  686. //----------------------------------------------------------------------------------------
  687.  
  688. inline void  FW_CString::operator+=(ODIText* text)
  689. {
  690.     FW_PlatformError error = 0;
  691.     FW_HString rep = FW_PrivString_AppendODIText(fRep, text, &error);
  692.     FW_FailOnError(error);
  693.     fRep = rep;
  694. }
  695.  
  696. //----------------------------------------------------------------------------------------
  697. //    FW_CString::operator+=
  698. //----------------------------------------------------------------------------------------
  699.  
  700. inline void  FW_CString::operator+=(const char* string)
  701. {
  702.     FW_PlatformError error = 0;
  703.     FW_HString rep = FW_PrivString_AppendBytes(fRep, string, FW_PrimitiveStringLength(string), &error);
  704.     FW_FailOnError(error);
  705.     fRep = rep;
  706. }
  707.  
  708. //----------------------------------------------------------------------------------------
  709. //    FW_CString::operator+=
  710. //----------------------------------------------------------------------------------------
  711.  
  712. inline void  FW_CString::operator+=(char character)
  713. {
  714.     FW_PlatformError error = 0;
  715.     FW_HString rep = FW_PrivString_AppendBytes(fRep, &character, 1, &error);
  716.     FW_FailOnError(error);
  717.     fRep = rep;
  718. }
  719.  
  720. //----------------------------------------------------------------------------------------
  721. //    FW_CString::ExportCString
  722. //----------------------------------------------------------------------------------------
  723.  
  724. inline void FW_CString::ExportCString(char* buffer) const
  725. {
  726.     FW_PrivString_ExportCString(fRep, buffer);
  727. }
  728.  
  729. //----------------------------------------------------------------------------------------
  730. //    FW_CString::ExportPascal
  731. //----------------------------------------------------------------------------------------
  732.  
  733. inline void FW_CString::ExportPascal(FW_PascalChar* buffer) const
  734. {
  735.     FW_PrivString_ExportPascalString(fRep, buffer);
  736. }
  737.  
  738. //----------------------------------------------------------------------------------------
  739. //    FW_CString::ToUpper
  740. //----------------------------------------------------------------------------------------
  741.  
  742. inline void FW_CString::ToUpper()
  743. {
  744.     FW_PlatformError error = 0;
  745.     FW_HString rep = FW_PrivString_ToUpper(fRep, &error);
  746.     FW_FailOnError(error);
  747.     fRep = rep;
  748. }
  749.  
  750. //----------------------------------------------------------------------------------------
  751. //    FW_CString::ToLower
  752. //----------------------------------------------------------------------------------------
  753.  
  754. inline void FW_CString::ToLower()
  755. {
  756.     FW_PlatformError error = 0;
  757.     FW_HString rep = FW_PrivString_ToLower(fRep, &error);
  758.     FW_FailOnError(error);
  759.     fRep = rep;
  760. }
  761.  
  762. //----------------------------------------------------------------------------------------
  763. //    FW_CString::Substitute
  764. //----------------------------------------------------------------------------------------
  765.  
  766. inline FW_Boolean FW_CString::Substitute(const FW_CString& searchString,
  767.                                   const FW_CString& substitutionString)
  768. {
  769.     FW_PlatformError error = 0;
  770.     FW_Boolean wasReplaced;
  771.     FW_HString rep = FW_PrivString_Substitute(fRep, searchString.fRep, substitutionString.fRep, &wasReplaced, &error);
  772.     FW_FailOnError(error);
  773.     fRep = rep;
  774.     return wasReplaced;
  775. }
  776.  
  777. //----------------------------------------------------------------------------------------
  778. //    FW_CString::FindSubString
  779. //----------------------------------------------------------------------------------------
  780.  
  781. inline FW_Boolean FW_CString::FindSubString(const FW_CString& subString,
  782.                                       FW_BytePosition &foundPosition,
  783.                                      FW_BytePosition startPosition) const
  784. {
  785.     return FW_PrivString_FindSubString(fRep, subString.fRep, &foundPosition, startPosition);
  786. }
  787.  
  788. //----------------------------------------------------------------------------------------
  789. //    FW_CString::FindCharacter
  790. //----------------------------------------------------------------------------------------
  791.  
  792. inline FW_Boolean FW_CString::FindCharacter(FW_LChar character,
  793.                                      FW_BytePosition &foundPosition,
  794.                                      FW_BytePosition startPosition,
  795.                                      FW_FindDirection direction) const
  796. {
  797.     return FW_PrivString_FindCharacter(fRep, character, &foundPosition, startPosition, direction);
  798. }
  799.  
  800. //----------------------------------------------------------------------------------------
  801. //    FW_CString::operator=
  802. //----------------------------------------------------------------------------------------
  803.  
  804. inline FW_CString& FW_CString::operator=(ODIText *text)
  805. {
  806.     ReplaceAll(text);
  807.     return *this;
  808. }
  809.  
  810. //----------------------------------------------------------------------------------------
  811. //    FW_CString::operator=
  812. //----------------------------------------------------------------------------------------
  813.  
  814. inline FW_CString& FW_CString::operator=(const char* string)
  815. {
  816.     ReplaceAll(string);
  817.     return *this;
  818. }
  819.  
  820. //----------------------------------------------------------------------------------------
  821. //    FW_CString::ReplaceAll
  822. //----------------------------------------------------------------------------------------
  823.  
  824. inline void FW_CString::ReplaceAll(const char* string, const FW_Locale& newLocale)
  825. {
  826.     FW_PlatformError error = 0;
  827.     FW_HString rep = FW_PrivString_AcquireEmptyStringWithLocale(newLocale, &error);
  828.     FW_FailOnError(error);
  829.     rep = FW_PrivString_ReplaceAllBytes(rep, string, FW_PrimitiveStringLength(string), &error);
  830.     FW_FailOnError(error);
  831.     fRep = rep;
  832. }
  833.  
  834. //----------------------------------------------------------------------------------------
  835. //    FW_CString::SetEmpty
  836. //----------------------------------------------------------------------------------------
  837.  
  838. inline void FW_CString::SetEmpty()
  839. {
  840.     FW_PrivString_Release(fRep);
  841.     fRep = FW_PrivString_AcquireEmptyString();    // locale = smRoman/langEnglish
  842. }
  843.  
  844. //----------------------------------------------------------------------------------------
  845. //    FW_CString::SetEmpty
  846. //----------------------------------------------------------------------------------------
  847.  
  848. inline void FW_CString::SetEmpty(const FW_Locale& newLocale)
  849. {
  850.     FW_PrivString_Release(fRep);
  851.     FW_PlatformError error = 0;
  852.     FW_HString rep = FW_PrivString_AcquireEmptyStringWithLocale(newLocale, &error);
  853.     FW_FailOnError(error);
  854.     fRep = rep;
  855. }
  856.  
  857. #endif
  858.